package pro.softzhang.algo.lc1600;

import java.util.Arrays;

public class LC1679_MaxNumberOfKSumPairs {
    public static void main(String[] args) {

    }

    static class Solution {
        public int maxOperations(int[] nums, int k) {
            int max = 0;
            Arrays.sort(nums);
            for(int p1 = 0, p2 = nums.length - 1; p1 < p2; ) {
                int sum = nums[p1] + nums[p2];
                if(sum == k) {
                    p1++;
                    p2--;
                    max++;
                } else if(sum < k) {
                    p1++;
                } else {
                    p2--;
                }
            }
            return max;
        }
    }
}
